package pack1;

import javax.swing.table.AbstractTableModel;

public class MyTableModel extends AbstractTableModel  {

        private static final boolean DEBUG = true;
		private String[] columnNames = {"",
                                        "Item Description",
                                        "Price",
                                        "",""
                                        };

        public int getColumnCount() {
        	Tabledesc tab = new Tabledesc();
            return tab.getColumnCount();
        }

        public int getRowCount() {
        	Tabledesc tab = new Tabledesc();
            return tab.getRowCount();
        }

        public String getColumnName(int col) {
            return columnNames[col];
        }

        public Object getValueAt(int row, int col) {
        	Tabledesc tab = new Tabledesc();
            return tab.getValueAt(row+1, col+1);
        }

        /*
         * JTable uses this method to determine the default renderer/
         * editor for each cell.  If we didn't implement this method,
         * then the last column would contain text ("true"/"false"),
         * rather than a check box.
         */
        public Class getColumnClass(int c) {
            return getValueAt(0, c).getClass();
        }

        /*
         * Don't need to implement this method unless your table's
         * editable.
         */
        public boolean isCellEditable(int row, int col) {
            //Note that the data/cell address is constant,
            //no matter where the cell appears onscreen.
            if (col < 1) {
                return false;
            } else {
                return true;
            }
        }

        /*
         * Don't need to implement this method unless your table's
         * data can change.
         */
        public void setValueAt(Object value, int row, int col) {
            if (DEBUG) {
                System.out.println("Setting value at " + row + "," + col
                                   + " to " + value
                                   + " (an instance of "
                                   + value.getClass() + ")");
            }
            
            Tabledesc tab = new Tabledesc();
            tab.setValueAt(row, col, value);
            
            
            
            
            fireTableCellUpdated(row, col);

            if (DEBUG) {
                System.out.println("New value of data:");
                printDebugData();
            }
        }

        private void printDebugData() {
            int numRows = getRowCount();
            int numCols = getColumnCount();
            for (int i=0; i < numRows; i++) {
                System.out.print("    row " + i + ":");
                for (int j=0; j < numCols; j++) {
                }
            }
        }

    /**
     * Create the GUI and show it.  For thread safety,
     * this method should be invoked from the
     * event-dispatching thread.
     */

}
